/**
 * Created by sisi.chen on 2016/6/2.
 */
'use strict';
define([
    '../../framework/base/baseView',
    '../../framework/bean/ecReport',
    'customCharts'
], function(
    BaseView,
    ecReportModel,
    customCharts
) {
    function me() {
        BaseView.apply(this, arguments);
        var self = this;
        this.defaultSelectd = 3;
        this.theme = {
            //网格
            grid: {
               // x: 50,
                y: 10,
                x2: 10,
                y2: 25,
                borderWidth: 0
            },
            // 默认色板
            color: ['#a2d5f9', '#b3d890', '#ead07d', '#d7d3f1', '#deb791',
                '#dba9a7', '#a9d8da', '#9accb1', '#bcbbd5', '#deaec7'],
            tooltip : {
                trigger: 'axis',
                backgroundColor: 'white',     // 提示背景颜色，默认为透明度
                borderWidth : 1,
                borderColor : '#cccccc',
                borderRadius: 0,
                padding: 10,
                axisPointer : {
                    type : 'shadow',
                    shadowStyle: {
                        color: 'rgba(238,238,238,0.6)',
                        width: 'auto',
                        type: 'default'
                    }
                },
                textStyle: {
                    color: '#666666'
                },
                position : function(p) {
                    // 位置回调
                    return [p[0] - 40, p[1] - 40];
                },
                enterable : true,
                hideDelay : 0,
                showDelay:0
            },
            //图列
            legend: {
                orient: 'horizontal',      // 布局方式，默认为水平布局，可选为：
                                           // 'horizontal' ¦ 'vertical'
                x: '80',               // 水平安放位置，默认为全图居中，可选为：
                // 'center' ¦ 'left' ¦ 'right'
                // ¦ {number}（x坐标，单位px）
                y: '267',                  // 垂直安放位置，默认为全图顶端，可选为：
                                           // 'top' ¦ 'bottom' ¦ 'center'
                                           // ¦ {number}（y坐标，单位px）
                backgroundColor: 'rgba(0,0,0,0)',
                borderColor: '#ccc',       // 图例边框颜色
                borderWidth: 0,            // 图例边框线宽，单位px，默认为0（无边框）
                //padding: 5,                // 图例内边距，单位px，默认各方向内边距为5，
                // 接受数组分别设定上右下左边距，同css
                itemGap: 10,               // 各个item之间的间隔，单位px，默认为10，
                                           // 横向布局时为水平间隔，纵向布局时为纵向间隔
                //itemWidth: 15,             // 图例图形宽度
                //itemHeight: 15,            // 图例图形高度
                textStyle: {
                    color: '#666666'          // 图例文字颜色
                },
                formatter : function(name){
                    return self.kit.translate("abTest", name);
                }
            },
            // 类目轴
            categoryAxis: {
                splitLine: {
                    show: false
                },
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    margin: 10,
                    textStyle: {
                        color: '#999999'
                    }
                }

            },
            // 数值型坐标轴默认参数
            valueAxis: {
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    margin: 10,
                    textStyle: {
                        color: '#999999'
                    }
                },
                splitLine: {
                    lineStyle: {
                        color: ['#eeeeee'],
                        width: 1,
                        type: 'solid'
                    }
                },
                formatter: function (value){
                    //return (value / 1000) + "K";
                    return self.kit.toThousands(value);
                }
            }
        }
        this.graph1Indicators = [ 'impressions','clicks','cart','purchase','costPerClick','costPerCart','costPerPurchase','incomePerPurchase']
        this.graph2Indicators = ['ctr','cartR','purchaseR','roi']
        this.graph3Indicators = [ 'impressions','clicks','cart','purchase','costPerClick','costPerCart','costPerPurchase','incomePerPurchase']
        this.init = function(feedId) {
            self.$root = $('.graph-container');
            //self.render();
        }
        this.render = function() {
          //
        }

        this.event = function() {

        }

        this.renderGraph = function(params) {
            self.graphs = [];
            ecReportModel.abGraph(params, function(results) {
                $(".graph-container").removeClass("hide");
                if(typeof results !="object" ){
                    $(".no-result", ".graph-container").show();
                    $(".graph-blocks", ".graph-container").hide();
                    return false;
                }

                $(".no-result", ".graph-container").hide();
                $(".graph-blocks", ".graph-container").show();
                self._renderGraph(params, results);
            });
        }

        this._renderGraph = function(_params, _results){
            var period = _params.day;
            var days = (moment(period.until).valueOf() - moment(period.since).valueOf()) / (24 * 60 * 60 * 1000);
            var xTimes = [];
            xTimes.push(period.since)
            var start =  moment(period.since);
            for (var i=1; i<=days; i++)
            {
                xTimes.push(start.add(1, 'days').format('YYYY-MM-DD'));
            }
            var barIndicators = {};
            var lineIndicators = {};
            var barIndicatorDimensions = [];
            $.each(_results.mapByIndicator, function(_k, _datas){
                if (_k == 'cartR' || _k == 'ctr' || _k == 'purchaseR' || _k == 'roi'){
                    lineIndicators[_k] = _datas;
                }
            })

            $.each(self.graph2Indicators, function(i, _k){
                if (_results.mapByIndicator[_k]){
                    lineIndicators[_k] = _results.mapByIndicator[_k];
                }
            });
            $.each(self.graph1Indicators, function(i, _k){
                if (_results.mapByIndicator[_k]){
                    barIndicatorDimensions.push(_k);
                    barIndicators[_k] = _results.mapByIndicator[_k];
                }
            })


            self.group = _params.group;
            self.graphs = [];

            if (xTimes.length <= 47 ){
                this.theme.bar = {
                    barWidth:15,
                    barGap :5,
                    barCategoryGap : '30'
                }
            } else {
                this.theme.bar = null;
            }

            //图一
            self.mapByIndicatorBar(xTimes, barIndicatorDimensions, barIndicators);

            //图二
            self.mapByIndicatorLine(xTimes, lineIndicators);

            //图三
            self.mapByDimension(xTimes, _results[_params.group], _results.mapByDimension);

            //图四
            self.radar(_results[_params.group], _results.radarData);

            if (self.graphs && self.graphs.length){
                window.onresize = function () {
                    if (self.graphs && self.graphs.length){
                        $.each(self.graphs, function(i, _graph){
                            _graph.resize();
                        })
                    }
                }
            }
        }

        this.mapByIndicatorLine = function(xTimes, lineIndicators){

            //清空图表
            $.each($(".line-single-graph"), function (i, _singleGraph) {
                $(_singleGraph).customCharts("destroy");
            })

            self.lineIndicatorCharts = [];
            var _indicatorLineComparisonChartOption = {
                //网格
                grid : {
                    x : 5,
                    y : 20,
                    x2 : 5,
                    y2 : 0,
                    borderWidth : 0
                },
                // 默认色板
                color: ['#a2d5f9', '#b3d890', '#ead07d', '#d7d3f1', '#deb791',
                    '#dba9a7', '#a9d8da', '#9accb1', '#bcbbd5', '#deaec7'],
                tooltip : {
                    trigger: 'axis',
                    formatter : function(params){
                        var res = "<div>" + params[0].name;
                        for (var i = 0, l = params.length; i < l; i++) {
                            res += '<br/>' +  self.kit.translate("abTest", params[i].seriesName) + ' : ' + Number(params[i].value * 100).toFixed(2) + '%';
                        }
                        res += "</div>";

                        var tooltips = $(".line-single-graph").find(".echarts-tooltip");
                        tooltips.off("scroll").on("scroll", function(){
                            var _ct = this;
                            $.each(tooltips, function(i, _tooltip){
                                if (_tooltip != _ct){
                                    $(_tooltip).scrollTop($(_ct).scrollTop());
                                    $(_tooltip).scrollLeft($(_ct).scrollLeft());
                                }
                            });
                        })

                        return res;
                    },
                    backgroundColor: 'white',     // 提示背景颜色，默认为透明度
                    borderWidth : 1,
                    borderColor : '#cccccc',
                    borderRadius: 0,
                    padding: 10,
                    axisPointer : {
                        type: 'line',
                        lineStyle: {
                            color: '#bbbbbb',
                            width: 1,
                            type: 'solid'
                        }
                    },
                    textStyle: {
                        color: '#666666'
                    },
                    position : function(p) {
                        // 位置回调
                        var _x = p[0];
                        // if (_x < 150){
                        //    $(".line-single-graph .echarts-tooltip").addClass("left-10");
                        //     $(".line-single-graph .echarts-tooltip").removeClass("left-128");
                        // } else {
                        //     $(".line-single-graph .echarts-tooltip").addClass("left-128");
                        //     $(".line-single-graph .echarts-tooltip").removeClass("left-10");
                        // }
                        if (_x >= 135.5){
                            return [p[0] + 30, p[1] - 80];
                        } else {
                            return [p[0] - 10, p[1] - 80];
                        }

                    },
                    enterable : true,
                    hideDelay : 0,
                    showDelay:0
                },
                xAxis : [
                    {
                        show : false,
                        type : 'category',
                        boundaryGap : false
                    }
                ],
                yAxis : [
                    {
                        show : false,
                        type : 'value'
                    }
                ],
                legend : {
                    show: false,
                    x: '0',
                    y:-180,
                    formatter : function(name){
                        return self.kit.translate("abTest", name);
                    }
                }
            };

            $(".indicator-line-comparison").empty();
            $(".indicator-line-comparison").parent().find(".graph-title").html(I18N.getText('abTest', 'differentPercentageComparison', self.kit.translate("abTest", self.group).toLowerCase()));
            var newLineIndicators = [
                { indicator : "ctr", datas : lineIndicators["ctr"]},
                { indicator : "cartR", datas : lineIndicators["cartR"]},
                { indicator : "purchaseR", datas : lineIndicators["purchaseR"]},
                { indicator : "roi", datas : lineIndicators["roi"]}
            ]
            var _size = newLineIndicators.length;
            var showCustomLegend = false;

            $.each(newLineIndicators, function(_k , _indicator){
                $(".indicator-line-comparison").append( _.template($('#indicator-line-comparison-t').text())({keyLabel :
                    self.kit.translate("abTest", _indicator.indicator), key : _indicator.indicator}));
                var legendData = [];
                var legendSelected = {};
                $.each(_indicator.datas, function(i, _data){
                    _data.clickable = false;
                    _data.type = "line";
                    _data.smooth = true;
                    _data.itemStyle = {normal: {areaStyle: {type: 'default'}}}
                    legendData.push(_data.name);
                    legendSelected[_data.name] = (Object.keys(legendSelected).length > self.defaultSelectd - 1) ? false : true;
                })
                _indicatorLineComparisonChartOption.xAxis[0].data = xTimes;
                _indicatorLineComparisonChartOption.series = _indicator.datas;
                _indicatorLineComparisonChartOption.legend.data = legendData;
                _indicatorLineComparisonChartOption.legend.selected = legendSelected;
                if (_k == (_size - 1)){
                    //_indicatorLineComparisonChartOption.grid.y2 = 20;
                    $("#" + _indicator.indicator + "_line").css("height", "110px");
                    _indicatorLineComparisonChartOption.legend.show = true;
                    showCustomLegend = true;
                    _indicatorLineComparisonChartOption.tooltip.formatter = function(params){
                        var res = params[0].name;
                        for (var i = 0, l = params.length; i < l; i++) {
                            res += '<br/>' + self.kit.translate("abTest", params[i].seriesName) + ' : ' + Number(params[i].value).toFixed(2) ;
                        }

                        return res;
                    }
                }

                var _indicatorLineComparisonChartE = $("#" + _indicator.indicator + "_line").customCharts({
                    option : _indicatorLineComparisonChartOption,
                    showCustomLegend : showCustomLegend
                });
                self.lineIndicatorCharts.push(_indicatorLineComparisonChartE);
                self.graphs.push(_indicatorLineComparisonChartE)
            })

            //共享图例
            customCharts.connect($(".line-single-graph"));
        }

        this.mapByIndicatorBar = function(xTimes, barIndicatorDimensions, _indicators){
            //清空图表
            $("#ndicator-bar-comparison").customCharts("destroy");

            $("#indicator-bar-comparison").parent().find(".graph-title").html(I18N.getText('abTest', 'differentDimensionSameIndicator', self.kit.translate("abTest", self.group).toLowerCase()));

            var defaultIndicatorDimension = barIndicatorDimensions[0];
            var dropDatas = [];
            $.each(barIndicatorDimensions, function(i, barIndicatorDimension){
                dropDatas.push({value : barIndicatorDimension, label: self.kit.translate("abTest", barIndicatorDimension)});
            })

            var _indicatorComparisonOption = {
                tooltip : {
                    trigger: 'axis',
                    formatter: function (params,ticket,callback) {
                        var res = params[0].name;
                        for (var i = 0, l = params.length; i < l; i++) {
                            res += '<br/>' + self.kit.translate("abTest", params[i].seriesName) + ' : ' + params[i].value;
                        }
                        return res;
                    },
                    enterable : true,
                    hideDelay : 0,
                    showDelay:0
                    ,
                    position : function(p) {
                        // 位置回调
                        if (p[0] >= 739){
                            return [p[0] + 20, p[1]];
                        } else {
                            return [p[0], p[1]];
                        }
                    }
                },
                xAxis : [
                    {
                        type : 'category'
                    }
                ],
                legend : {
                    formatter : function(name){
                        return self.kit.translate("abTest", name);
                    }
                }
            }
            _indicatorComparisonOption.xAxis[0].data =  xTimes

            $('div.dropdown[name="indicators"]').empty().drop2({
                type:2,
                caret:"<i class='glyphicon glyphicon-menu-down'></i>",
                data:dropDatas
            }).off("SELECT_CHANGE").on("SELECT_CHANGE",function(e){
                var cindicator = e.originalEvent.data.value;
                initChart(cindicator);
                //self._indicatorComparisonChart.clear();
                //self._indicatorComparisonChart.setOption(_indicatorComparisonOption);
                $("#indicator-bar-comparison").customCharts("update", _indicatorComparisonOption);
            }).val(dropDatas[0]); //默认 显示的值 默认显示下拉列表中的第一个
            initChart(defaultIndicatorDimension);
            // self._indicatorComparisonChart = echarts.init(document.getElementById('indicator-bar-comparison'), self.theme);
            // self._indicatorComparisonChart.setOption(_indicatorComparisonOption);
            var _indicatorComparisonChart = $("#indicator-bar-comparison").empty().customCharts({
                theme : self.theme,
                option : _indicatorComparisonOption
            });
            self.graphs.push(_indicatorComparisonChart)

            function initChart(cindicator){
                var isMoney = false;
                var yAxis = [
                    {
                        type : 'value',
                        axisLabel : {
                            formatter: function (value){
                                //return Number(value / 1000).toFixed(0) + "K";
                                return self.kit.toThousands(value);
                            }
                        }
                    }
                ];

                _indicatorComparisonOption.tooltip.formatter = function (params,ticket,callback) {
                    var res = params[0].name;
                    for (var i = 0, l = params.length; i < l; i++) {
                        res += '<br/>' + self.kit.translate("abTest", params[i].seriesName) + ' : ' + params[i].value;
                    }

                    return res;
                }

                if (cindicator == 'budget' || cindicator == 'costPerCart' || cindicator == 'costPerClick'
                    || cindicator == 'costPerMile' || cindicator == 'costPerPurchase' || cindicator == 'incomePerPurchase' || cindicator == 'spend'){
                    yAxis =  [
                        {
                            type : 'value',
                            axisLabel : {
                                formatter: '${value}'
                            }
                        }
                    ];
                    _indicatorComparisonOption.tooltip.formatter = function (params,ticket,callback) {
                        var res = params[0].name;
                        for (var i = 0, l = params.length; i < l; i++) {
                            res += '<br/>' + self.kit.translate("abTest", params[i].seriesName) + ' : $' + params[i].value;
                        }

                        return res;
                    }
                    isMoney = true;
                }

                var changedIndicators = _indicators[cindicator];
                var legend = [];
                var _news = [];
                var legendSelected = {};
                $.each(changedIndicators, function(i, _data){
                    var _newData = {
                        name : _data.name,
                        type : 'bar',
                        data :  _data.data,
                        clickable : false
                    }
                    legend.push(_newData.name);
                    legendSelected[_newData.name] = (Object.keys(legendSelected).length > self.defaultSelectd - 1) ? false : true;
                    if (isMoney && _newData.data && _newData.data.length){
                        var newData = [];
                        $.each(_data.data, function(i, _sdata){
                            newData.push(Number(Number(_sdata / 100).toFixed(2)));
                        })
                        _newData.data = newData;
                    }
                    _news.push(_newData)
                });

                _indicatorComparisonOption.legend.data = legend;
                _indicatorComparisonOption.legend.selected = legendSelected;
                console.log( _indicatorComparisonOption.legend.selected)
                _indicatorComparisonOption.series = _news;
                _indicatorComparisonOption.yAxis = yAxis;
            }
        }

        this.mapByDimension = function(xTimes, dimensions, mapByDimension){
            //清空图表
            $("#dimension-comparison").customCharts("destroy");

            $("#dimension-comparison").parent().find(".dimension-label").html(self.kit.translate('abTest', self.group + "Colon"));
            $("#dimension-comparison").parent().find(".graph-title").html(I18N.getText("abTest", "differentIndicatorSameDimension", self.kit.translate('abTest', self.group).toLowerCase()));
            var dropDatas = [];
            $.each(dimensions, function(i, dimension){
                dropDatas.push({
                    label : self.kit.translate("abTest", dimension), value: dimension
                })
            })
            var _dimensionComparisonOption = {
                color:['#dd9666','#eaad5f','#f1cd62','#ecd58e','#ddd487','#bad58b','#9bcc8e','#86c1a9','#90bac6','#95a9d5'],
                legend: {
                    formatter : function(name){
                        return self.kit.translate("abTest", name);
                    }
                },
                tooltip : {
                    trigger: 'axis',
                    formatter: function (params,ticket,callback) {
                        var res = params[0].name;
                        for (var i = 0, l = params.length; i < l; i++) {
                            var _sn = params[i].seriesName;
                            var unit = ""
                            if ("costPerClick" == _sn || "costPerCart" == _sn || "costPerPurchase" == _sn || "incomePerPurchase" == _sn){
                                unit = "$";
                            }
                            res += '<br/>' + self.kit.translate("abTest", params[i].seriesName) + ' : ' + unit + params[i].value;
                        }
                        return res;
                    },
                    enterable : true,
                    hideDelay : 0,
                    showDelay:0
                },
                xAxis : [
                    {
                        type : 'category'
                    }
                ],
                yAxis : [
                    {
                        type : 'value',
                        axisLabel : {
                            formatter: function (value){
                                //return Number(value / 1000).toFixed(0) + "K";
                                return self.kit.toThousands(value);
                            }
                        }
                    },
                    {
                        type : 'value',
                        axisLabel : {
                            formatter: '${value}'
                        }
                    }
                ]
            }
            var defaultDimension = dimensions[0];
            $('div.dropdown[name="dimensions"]').empty().drop2({
                type:2,
                caret:"<i class='glyphicon glyphicon-menu-down'></i>",
                data:dropDatas
            }).off("SELECT_CHANGE").on("SELECT_CHANGE",function(e){
                initChart(mapByDimension[e.originalEvent.data.value]);
                $("#dimension-comparison").customCharts("update", _dimensionComparisonOption);
            }).val(dropDatas[0]); //默认 显示的值 默认显示下拉列表中的第一个

            self.theme.grid.x2 = 40;
            initChart(mapByDimension[defaultDimension]);
            var _dimensionComparisonChart = $("#dimension-comparison").empty().customCharts({
                theme : self.theme,
                option : _dimensionComparisonOption
            });
            self.graphs.push(_dimensionComparisonChart)
            function initChart(datas){
                var series = [];
                var legend = [];
                var mapDatas = {};
                $.each(datas, function(i, _data){
                    var _newData = {
                        name : _data.name,
                        data : _data.data,
                        clickable : false
                    };

                    var _index = self.graph3Indicators.indexOf(_data.name);
                    if (_index > -1 &&  _index >= 4){
                        _newData.type = "line";
                        _newData.yAxisIndex = 1;
                        if (_newData.data && _newData.data.length){
                            var _ndata = [];
                            $.each(_newData.data, function(i, _sdata){
                                _ndata.push(Number(_sdata/100).toFixed(2));
                            })
                            _newData.data = _ndata;
                        }
                        mapDatas[_newData.name] = _newData;
                    }

                    if (_index > -1 &&  _index < 4){
                        _newData.type = "bar";
                        mapDatas[_newData.name] = _newData;
                    }
                });
                $.each(self.graph3Indicators, function(i, _indicator){
                    if (mapDatas[_indicator]){
                        series.push(mapDatas[_indicator]);
                        legend.push(_indicator)
                    }
                });
                _dimensionComparisonOption.legend.data = legend;
                _dimensionComparisonOption.xAxis[0].data = xTimes;
                _dimensionComparisonOption.series = series;
            }
        }

        this.radar = function(_dimensions, radarDatas){
            //清空图表
            $("#radar-graph").customCharts("destroy");

            var radarOption = {
                color:['#a2d5f9', '#b3d890', '#ead07d', '#d7d3f1', '#deb791',
                '#dba9a7', '#a9d8da', '#9accb1', '#bcbbd5', '#deaec7'],
                tooltip : {
                    formatter : function(params){
                        var res = "";
                        if (params.length){
                            var _in = params[0].indicator
                            res += _in + "</br>";
                            $.each(params, function(i, _param){
                                var _unit = "";
                                if (_param.dataIndex != 5){
                                    _unit = "$";
                                }
                                res += self.kit.translate("abTest", _param.name) + " : " + _unit;
                                res += Number(_param.value);
                                res += "</br>";
                            })
                        }
                        return res;
                    },
                    trigger: 'axis',
                    backgroundColor: 'white',     // 提示背景颜色，默认为透明度
                    borderWidth : 1,
                    borderColor : '#cccccc',
                    borderRadius: 0,
                    padding: 10,
                    axisPointer : {
                        type: 'line',
                        lineStyle: {
                            color: '#bbbbbb',
                            width: 1,
                            type: 'solid'
                        }
                    },
                    textStyle: {
                        color: '#666666'
                    },
                    position : function(p) {
                        // 位置回调
                        if (p[0] > 213){
                            return [p[0] + 40, p[1]];
                        } else {
                            return [p[0], p[1]];
                        }

                        //return [p[0], p[1]];
                    },
                    enterable : true,
                    hideDelay : 0,
                    showDelay:0
                },
                legend: {
                    orient : 'horizontal',
                    x : 'left',
                    y : 286,
                    formatter : function(name){
                        return self.kit.translate("abTest", name);
                    }
                },
                polar : [
                    {
                        radius:'65%',
                        name : {
                            textStyle: {
                                color: '#999999'
                            },
                            formatter: function(param){
                                return param
                            }
                        },
                        splitNumber : 4,
                        splitArea: {
                            show: false
                        },
                        splitLine: {
                            show: true,
                            lineStyle : {
                                color: '#eeeeee',
                                width: 1,
                                type : 'dotted'
                            }
                        }
                    }
                ]
            };

            var dindicator =  [
                { text: self.kit.translate("abTest", "costPerClick"), max: 2},
                { text: self.kit.translate("abTest", 'costPerCart'), max: 2},
                { text: self.kit.translate("abTest", 'costPerPurchase'), max: 31},
                { text: self.kit.translate("abTest", "incomePerPurchase"), max: 78},
                { text: self.kit.translate("abTest", "CPM"), max: 14},
                { text: self.kit.translate("abTest", "ROI"), max: 4}
            ]
            radarOption.polar[0].indicator = dindicator;


            var lengend = _dimensions;
            var legendSelected = {};
            $.each(_dimensions, function(i, _dimension){
                legendSelected[_dimension] = (Object.keys(legendSelected).length > self.defaultSelectd - 1) ? false : true;
            })

            if (radarDatas && radarDatas.length){
                var indicators = [];
                $.each(radarDatas, function(i, _radarData){
                    if (_radarData.value && _radarData.value.length){
                        var news = []
                        $.each(_radarData.value, function(j, _v){
                            var nv;
                            if (j != 5){
                                nv = Number(_v / 100).toFixed(2);
                            } else {
                                nv = Number(_v).toFixed(2);
                            }
                            news.push(nv)
                            //动态最大值
                            if (indicators[j] != undefined){
                                if (Number(nv) > Number(indicators[j])){
                                    indicators[j] = nv;
                                }
                            } else {
                                indicators[j] = nv;
                            }
                        })
                        _radarData.value = news;
                    }
                })

                if (indicators.length){
                    var newindicator = [];
                    $.each(indicators, function(i, _max){
                        newindicator.push({
                            text : dindicator[i].text,
                            max : Number(Number(_max / 0.7).toFixed(2))
                        })
                    })
                    radarOption.polar[0].indicator = newindicator;
                }
            }

            var datas = []
            datas.push({
                type: 'radar',
                data : radarDatas,
                clickable : false
            })
            radarOption.legend.data = lengend;
            radarOption.legend.selected = legendSelected;
            radarOption.series = datas;
            var _radarChart = $("#radar-graph").empty().customCharts({
                option : radarOption
            });
            self.graphs.push(_radarChart)
        }

        this.destroy = function() {
            self.$root.empty();
        }

    }
    return me;
});
